﻿using System;
using System.Windows.Forms;
using HighDiveEngine.Aggregates;
using HighDiveEngine.Model;
using HighDiveEngine.Resources;

namespace HighDiveAdmin.GUI.Components
{
    public partial class WelcomeScreen : UserControl
    {
        public event MethodInvoker EventCreateContest;
        public event MethodInvoker EventStartContest;
        public event MethodInvoker EventEditContest;
        public event DelegateVoidContest EventEditUpcoming;
        public event MethodInvoker EventExit;

        public WelcomeScreen()
        {
            InitializeComponent();
        }

        #region ButtonClickEvents
        private void buttonCreateContest_Click(object sender, EventArgs e)
        {
            if (EventCreateContest != null)
                EventCreateContest();
        }

        private void buttonStartResumeContest_Click(object sender, EventArgs e)
        {
            if (EventStartContest != null)
                EventStartContest();
        }

        private void buttonEditContest_Click(object sender, EventArgs e)
        {
            if (EventEditContest != null)
                EventEditContest();
        }
        private void listBoxUpcomingContests_Click(object sender, MouseEventArgs e)
        {
            if (e.Y <= listBoxUpcomingContests.SelectedIndex*15 || e.Y >= listBoxUpcomingContests.SelectedIndex*15 + 15)
                return;
            if (EventEditUpcoming != null)
                EventEditUpcoming((Contest)listBoxUpcomingContests.Items[listBoxUpcomingContests.SelectedIndex]);
        }
        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (EventExit != null)
                EventExit();
        }
        private void buttonStartResumeContest_VisibleChanged(object sender, EventArgs e)
        {
            if (Visible)
                buttonStartResumeContest.Focus();
        }

        #endregion

        #region FillFunctions

        public void FillUpcomingContests(ContestList contestList)
        {
            listBoxUpcomingContests.DataSource = contestList;
        }
        #endregion

        private void listBoxUpcomingContests_KeyDown(object sender, KeyEventArgs e)
        {
            if(e.KeyData.HasFlag(Keys.Enter))
                if (EventEditUpcoming != null)
                    EventEditUpcoming((Contest)listBoxUpcomingContests.Items[listBoxUpcomingContests.SelectedIndex]);
        }

    }
}
